<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta charset="utf-8"/>
    <title>管理系统</title>

    <meta name="description" content=""/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"/>
    <link rel="stylesheet" th:href="@{/css/bootstrap.min.css}"/>
    <link rel="stylesheet" th:href="@{/font-awesome/4.5.0/css/font-awesome.min.css}"/>
    <link rel="stylesheet" th:href="@{/css/fonts.googleapis.com.css}"/>
    <link rel="stylesheet" th:href="@{/css/ace.min.css}" class="ace-main-stylesheet" id="main-ace-style"/>
    <link rel="stylesheet" th:href="@{/css/ace-part2.min.css}" class="ace-main-stylesheet"/>
    <link rel="stylesheet" th:href="@{/css/ace-skins.min.css}"/>
    <link rel="stylesheet" th:href="@{/css/ace-rtl.min.css}"/>
    <link rel="stylesheet" th:href="@{/css/ace-ie.min.css}"/>
    <link rel="stylesheet" th:href="@{/css/dataTables.bootstrap4.min.css}"/>
    <script th:src="@{/js/ace-extra.min.js}"></script>
    <script th:src="@{/js/html5shiv.min.js}"></script>
    <script th:src="@{/js/respond.min.js}"></script>
</head>

<body class="no-skin">
<!--头导航栏-->
<div th:replace="common/bar::#navbar"></div>
<div class="main-container ace-save-state" id="main-container">
    <script type="text/javascript">
        try {
            ace.settings.loadState('main-container')
        } catch (e) {
        }
    </script>
    <!-- 侧导航栏 -->
    <div th:replace="common/bar::#sidebar"></div>

    <div class="main-content">
        <div class="main-content-inner">
            <div class="breadcrumbs ace-save-state" id="breadcrumbs">
                <ul class="breadcrumb">
                    <li>
                        <i class="ace-icon fa fa-home home-icon"></i>
                        <a href="#">sys</a>
                    </li>
                    <li class="active">index</li>
                </ul><!-- /.breadcrumb -->
            </div>
            <div th:replace="common/modal::#msg_modal"></div>
            <div class="modal fade" id="report_reject_modal">
                <div class="modal-dialog modal-sm">
                    <div class="modal-content">
                        <!-- 模态框头部 -->
                        <div class="modal-header">
                            <h4 class="modal-title">填写驳回原因</h4>
                            <button type="button" class="close" data-dismiss="modal">&times;</button>
                        </div>
                        <!-- 模态框主体 -->
                        <div class="modal-body">
                            <textarea class="form-control" id="rejectMsg"
                                      placeholder="填写..."></textarea>
                        </div>
                        <!-- 模态框底部 -->
                        <div class="modal-footer">
                            <button type="button" class="btn btn-success" id="reportRejectButton" data-dismiss="modal">
                                提交
                            </button>
                            <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
                        </div>
                    </div>
                </div>
            </div>
            <div class="page-content">
                <div class="row">
                    <div class="col-xs-12 col-sm-3 widget-box">
                        <div class="widget-header">
                            <h4 class="widget-title" style="color: black">选择分类</h4>
                        </div>
                        <select class="form-control" id="select_client" multiple="multiple"
                                style="height:0px;padding-bottom: 100%;">
                        </select>
                    </div>
                    <div class="col-xs-12 col-sm-9 table-responsive">
                        <table class="table table-bordered table-hover text-nowrap" id="dateTable"
                               cellspacing="0">
                            <thead>
                            <tr>
                                <th>报告id</th>
                                <th>报告编号</th>
                                <th>检测日期</th>
                                <th>姓名/单位</th>
                                <th>创建时间</th>
                                <th>状态</th>
                                <th>审核人</th>
                                <th>签发人</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div><!-- /.page-content -->
        </div>
    </div><!-- /.main-content -->

    <div class="footer">
        <div class="footer-inner">
            <div class="footer-content">
                <span class="bigger-120">
                    <span class="blue bolder">公里派</span>
                    管理系统 &copy; 2020
                </span>
            </div>
        </div>
    </div>

    <a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
        <i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
    </a>
</div><!-- /.main-container -->
<script th:src="@{/js/jquery-2.1.4.min.js}"></script>
<script th:src="@{/js/jquery-1.11.3.min.js}"></script>
<script th:src="@{/js/bootstrap.min.js}"></script>
<script th:src="@{/js/ace-elements.min.js}"></script>
<script th:src="@{/js/ace.min.js}"></script>
<script th:src="@{/js/jquery.dataTables.min.js}"></script>
<script th:src="@{/js/dataTables.bootstrap4.min.js}"></script>
<!--公共js ， 有装载dateTable的公共js-->
<script th:src="@{/custom/common.js}"></script>
</body>
<script>
    var columns = [
        {"data": "reportId", visible: false},
        {"data": "jcbgbh"},
        {"data": "jxjcrq"},
        {"data": "xmdw"},
        {
            "data": "createTime",
            render: function (data, type, full) {
                return new Date(data).toLocaleDateString();
            }
        },
        {
            "data": "status",
            render: function (data, type, full) {
                return getStatusName(data,full.reportId);
            }
        },
        {
            "data":"auditName",
        },
        {
            "data":"ratifyName",
        },
        {
            render: function (data, type, full) {
                var temp = "<button onclick='report_view(" + full.reportId + ");'  class='btn btn-info btn-sm'> 查看</button>";
                if ([[${status?:0}]] == 1) {
                    temp += "<button onclick='report_pass(" + full.reportId + "," + 2 + ");'  class='btn btn-success btn-sm'>通过</button>";
                    temp += "<button onclick='report_reject(" + full.reportId + "," + 3 + ");'  class='btn btn-warning btn-sm'>驳回</button>";
                } else if ([[${status?:0}]] == 2) {
                    temp += "<button onclick='report_pass(" + full.reportId + "," + 4 + ");'  class='btn btn-success btn-sm'>通过</button>";
                    temp += "<button onclick='report_reject(" + full.reportId + "," + 5 + ");'  class='btn btn-warning btn-sm'>驳回</button>";
                } else if ([[${status?:0}]] == 4) {
                    temp += "<button onclick='report_print(" + full.reportId + ");'  class='btn btn-default btn-sm'>打印</button>";
                    temp += "<button onclick='report_archive(" + full.reportId + "," + 7 + ");'  class='btn btn-success btn-sm'>归档</button>";
                } else if ([[${status?:0}]] == 6) {

                }
                return temp;
            },
        }
    ];
    $(function () {
        load_table("/report/getList?status=[[${status}]]", columns);
        //装载选择委托单位
        $.ajax({
            type: "get",
            url: "/user/getClient",
            success: function (res) {
                $("#select_client").append("<option value='0'>所有</option>");
                $.each(res, function (index, item) {
                    $("#select_client").append("<option value='" + item.userId + "'>" + item.holder + "</option>");
                });
            }
        });
    });

    function report_view(reportId) {
        window.location.href = "/report/submit-view?reportId=" + reportId;
    }

    $("#select_client").change(function () {
        load_table("/report/getList?client=" + $(this).val() +"&status=[[${status}]]", columns);
    });

    function report_remove(reportId) {
        if (confirm("确认删除？")) {
            $.ajax({
                type: "post",
                url: "/report/remove?reportId=" + reportId,
                success: function (res) {
                    $("#dateTable").DataTable().ajax.reload();
                }
            })
        }
    }

    function report_pass(reportId, status) {
        if (confirm("确认通过？")) {
            $.ajax({
                method: "post",
                data: JSON.stringify({"reportId": reportId, "status": status}),
                url: "/report/audit",
                contentType: "application/json;charset=utf-8",
                success: function (res) {
                    $("#dateTable").DataTable().ajax.reload();
                }
            })
        }
    }

    function report_reject(reportId, status) {
        var c = JSON.stringify({"reportId": reportId, "status": status,"msg":$("#rejectMsg").val()});
        $("#report_reject_modal").modal("show");
        $("#reportRejectButton").click(function () {
            $.ajax({
                method: "post",
                data: JSON.stringify({"reportId": reportId, "status": status,"msg":$("#rejectMsg").val()}),
                url: "/report/audit",
                contentType: "application/json;charset=utf-8",
                success: function (res) {
                    $("#dateTable").DataTable().ajax.reload();
                }
            })
        });
    }
    function report_print(reportId) {
        if (confirm("确认下载？可能会比较慢，请勿重复刷新页面！")) {
            window.location.href = "/report/print?reportId="+reportId;
        }
    }
    function report_archive(reportId,status) {
        if (confirm("确认归档？")) {
            $.ajax({
                method: "post",
                data: JSON.stringify({"reportId": reportId, "status": status}),
                url: "/report/archive",
                contentType: "application/json;charset=utf-8",
                success: function (res) {
                    $("#dateTable").DataTable().ajax.reload();
                }
            })
        }
    }
</script>
</html>
